<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script src="../js/topfoot.js"></script>
    <link rel="stylesheet" href="../css/home.css">
</head>
<script>
    $(function () {
        let data = myAjax("frontHome", "", "get");
        getHomeNews(data[0].news);
        getHomeProduct(data[0].product);
    });

    function getHomeNews(data) {
        data = JSON.parse(data);
        let html = '';
        for (let i = 0; i < data.length; i++) {
            html += ' <div class="homenews">\n' +
                '                     <a href="javascript:getNewsDetailId(' + data[i].id + ')"><h5>' + data[i].title + '</h5></a>\n' +
                '                    <div>' + data[i].content + '</div>\n' +
                '                </div>';
        }
        $("#home-news").html(html);
    }

    function getHomeProduct(data) {
        data = JSON.parse(data);
        console.log(data);
        let html = '';
        for (let i = 0; i < data.length; i++) {
            html += ' <div class="floatleft">\n' +
                '                <div><img src="' + data[i].imgUrl + '"/></div>\n' +
                '                <a href="javascript:getProductDetailId(' + data[i].id + ')"><h5>' + data[i].name + '</h5></a>\n' +
                '                <div>' + data[i].content + '</div>\n' +
                '            </div>';
        }
        $("#home-product").html(html);
    }

    function getProductDetailId(id) {
        sessionStorage.setItem("productId", id);
        window.open("/html/product-detail.html");
    }
    function getNewsDetailId(id) {
        sessionStorage.setItem("newsDetailId", id);
        myAjax("updateNum", {id: id}, "get");
        window.open("/html/news-detail.html");
    }
</script>
<body>
<div id="tophtml"></div>
<div class="content">
    <div class="homeblock homeleft floatleft">
        <div class="hometitleleft">较新动态</div>
        <div class="homenewsblock">
            <div class="floatleft"><img src="../img/m331.jpg" height="250" width="270"/></div>
            <div class="floatleft" id="home-news">
                <!--                <div class="homenews">-->
                <!--                    <h5>日本较大抹茶餐饮七叶和茶登陆上海</h5>-->
                <!--                    <div>日本较大的抹茶餐饮连锁正式登陆上海，其中</div>-->
                <!--                </div>-->
                <!--                <div class="homenews">-->
                <!--                    <h5>日本较大抹茶餐饮七叶和茶登陆上海</h5>-->
                <!--                    <div>日本较大的抹茶餐饮连锁正式登陆上海，其中</div>-->
                <!--                </div>-->
                <!--                <div class="homenews">-->
                <!--                    <h5>日本较大抹茶餐饮七叶和茶登陆饮七叶和茶登陆上海</h5>-->
                <!--                    <div>日本较大的抹茶餐饮连锁大的抹茶餐饮连锁大的抹茶餐饮连锁大的抹茶餐饮连锁正式登陆上海，其中</div>-->
                <!--                </div>-->

            </div>
        </div>
    </div>
    <div class="homeblock homeright floatright">
        <div class="hometitleright">产品展示</div>
        <div class="homenewsblock" id="home-product">
            <!--            <div class="floatleft">-->
            <!--                <div><img src="../img/48_j53b.jpg"/></div>-->
            <!--                <a href="product-detail.html"><h6>蚂蚁上树</h6></a>-->
            <!--                <div>粉丝200g，猪肉馅50g</div>-->
            <!--            </div>-->
            <!--            <div class="floatright">-->
            <!--                <div><img src="../img/48_j53b.jpg"/></div>-->
            <!--                <a href="product-detail.html"><h6>蚂蚁上树</h6></a>-->
            <!--                <div>粉丝200g，猪肉馅50g</div>-->
            <!--            </div>-->
        </div>
    </div>
</div>
<div id="foothtml"></div>
</body>
</html>